#include "widget.h"
#include "ui_widget.h"
#include <QListView>
#include <QModelIndex>


Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);


    m_pListModel = new QStringListModel();

    QStringList strList;
    for(int i = 0; i < 10; i++){
        strList<<QString(QChar(65+i));
    }

    m_pListModel->setStringList(strList);
    ui->listView->setModel(m_pListModel);
    ui->listView->setAlternatingRowColors(true); //启用交替颜色
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_add_clicked()
{
    m_pListModel->insertRow(m_pListModel->rowCount());
    QModelIndex index = m_pListModel->index(m_pListModel->rowCount() - 1, 0);
    m_pListModel->setData(index,ui->lineEdit->text());
    m_pListModel->setData(index,ui->lineEdit->text() + "Tip",Qt::ToolTipRole);
}

void Widget::on_pushButton_del_clicked()
{
    m_pListModel->removeRow(ui->listView->currentIndex().row());
}
